/*
 * v1.1 by tonydon site:txdnet.cn
 * netbeansIDE 7.1
 */
package cn.txdnet.txweb.utils;

import java.util.concurrent.*;
/**
 *
 * @author txdnet
 */
public class Execute {
    
   private static ThreadPoolExecutor threadPool = Execute.getThreadPool();
           
   private static ThreadPoolExecutor getThreadPool(){
//        ReuseTaskExecutor task = new ReuseTaskExecutor();
//         task.setIntBatchAddTaskNum(32);
//         task.setPeriodms(8000);
//         RejectedExecutionHandler rejectedHandler = task.getRejectedHandler();
       ThreadPoolExecutor _threadPool =  new ThreadPoolExecutor(
            1, //corePoolSize
            3, //maxPoolSize 
            120, //keepAliveSeconds
            TimeUnit.SECONDS, 
            new ArrayBlockingQueue(32),  //workQueueSize
            new ThreadPoolExecutor.CallerRunsPolicy() //      rejectedHandler
        );
//       task.setThreadPoolExecutor(_threadPool);
       return _threadPool;
   }
   
   public static void run(Runnable r){
       Execute.threadPool.execute(r);
   }
   
   public static Future run(Callable c){
      return Execute.threadPool.submit(c);
   }
   
}